﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FormMdiTest
{
    public class Bird
    {
        public string Id { get; set; }
    }

    public class Sparrow : Bird
    {
        public string Name { get; set; }
    }

    /// <summary>
    /// 1.如果某个返回类型可以由其派生类替换，那这个类型就支持协变
    /// 2.如果某个参数类型可以由其父类替换，那这个类型就支持逆变
    /// </summary>
    public class XieBianNiBianTest
    {
        Sparrow bird = new Sparrow();
        IList<Bird> birdList = new List<Sparrow>().Select((c) => (Bird)c).ToList();//没有协变得时候需要将Sparrow 强制转化成父类。
        IEnumerable<Bird> birds = new List<Sparrow>();//协变得应用，返回

        ICustomListOut<Sparrow> cusBirds = new CustomListOut<Sparrow>();
        CustomListOut<Sparrow> cusBirdss = new CustomListOut<Sparrow>();
        private void XieBianTest()
        {
            Bird b = cusBirds.Get();

            cusBirdss.Show(bird);
        }

        ICustomListIn<Sparrow> sparrow = new CustomListIn<Sparrow>();
        ICustomListIn<Sparrow> sparrows = new CustomListIn<Bird>();
        private void NiBianTest()
        {
            Bird bird = new Bird();
            //sparrows.Show();
        }



    }

    public interface ICustomListOut<out T>
    {
        T Get();
        //void Show(T t); //不能作为参数类型的
    }

    public class CustomListOut<T> : ICustomListOut<T>
    {
        public T Get()
        {
            throw new NotImplementedException();
        }

        public void Show(T t)
        {

        }

    }

    public interface ICustomListIn<in T> 
    {
        //T Get(); 不能作为返回类型参数
        void Show(T t);
    }
    public class CustomListIn<T> : ICustomListIn<T>
    {
        public void Show(T t)
        {
            throw new NotImplementedException();
        }

        T Get()
        {
            return default(T);
        }
    }
}
